package Controller.Eboard;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import utility.Paging;
import Bean.eboardBean;
import Bean.rowBean;
import Dao.eboardDao;

public class EboardlistContoller implements Controller {
	private eboardDao dao;
	Paging pageInfo=null;
	public void setDao(eboardDao dao){
		this.dao = dao;
	}

	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse arg1) throws Exception {
		
		String pageNumber = request.getParameter("pageNumber");
		String pageSize = request.getParameter("pageSize");
		
		String uri=request.getRequestURI();
		String contextpath=request.getContextPath();
		String command=uri.substring(contextpath.length());
		
		int totalCount=dao.getTotal();
	    System.out.println(totalCount);
		System.out.println(pageNumber);
		System.out.println(pageSize);
		

		String url = contextpath +"/eboardlist.eboard" ;
		
		pageInfo = new Paging(pageNumber, pageSize, totalCount, url);
		
		rowBean row = new rowBean();
		row.setBeginRow(pageInfo.getBeginRow());
		row.setEndRow(pageInfo.getEndRow());
		
		List<eboardBean> eboardlist = dao.geteboardlist(row);
		ModelAndView mav = new ModelAndView();
		mav.setViewName("eboardlist");
		mav.addObject("eboardlist", eboardlist);
		mav.addObject("pageInfo", pageInfo);
		return mav;
		
	}
	
}
